home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / bc_ti.zip / TI734.ASC < prev    next >
Text File  |  1992-02-25  |  2KB  |  133 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                            NUMBER  :  734
  9.   VERSION  :  2.0
  10.        OS  :  DOS
  11.      DATE  :  February 25, 1992                        PAGE  :  1/2
  12.  
  13.     TITLE  :  Determining Stack Size
  14.  
  15.  
  16.  
  17.  
  18.  
  19.  
  20.   /************************************************************************
  21.   NEAR MEMORY MODELS:
  22.   In the near memory models the stack resides in the data segment.
  23.   It begins at the end of DGROUP and grows down in memory towards
  24.   SS & DS.  The variable __brklvl always marks the top of the heap.
  25.   The stack is allowed to grow until SP reaches __brklvl at which
  26.   time a stack overflow will be generated if stack checking is
  27.   turned on else the heap will be overwritten as the stack grows.
  28.  
  29.  
  30.   FAR MEMORY MODELS:
  31.   The stack starts in high memory just prior to _heapbase and grows
  32.   down towards SS.
  33.  
  34.  
  35.   This code example shows how to check the size of the stack at run
  36.   time.
  37.  
  38.  
  39.   written by:
  40.      Jerry Shockley    9/18/91
  41.  
  42.   ************************************************************************/
  43.   #include <stdio.h>
  44.   #include <conio.h>
  45.  
  46.   unsigned long stack();
  47.  
  48.   void main()
  49.   {
  50.  
  51.      unsigned long size = stack();
  52.      printf("\nStack size = %lu",size);
  53.   }
  54.  
  55.   unsigned long stack()
  56.   {
  57.       unsigned long ret;
  58.       extern unsigned long _heapbase;   //Beginning of the far heap
  59.       extern  unsigned __brklvl;        //End of the near heap
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                            NUMBER  :  734
  75.   VERSION  :  2.0
  76.        OS  :  DOS
  77.      DATE  :  February 25, 1992                        PAGE  :  2/2
  78.  
  79.     TITLE  :  Determining Stack Size
  80.  
  81.  
  82.  
  83.  
  84.       clrscr();
  85.   #if defined (__COMPACT__) || defined (__LARGE__) || defined
  86.   (__HUGE__)
  87.       ret = 16 * (*((unsigned *)_heapbase + 1) - _SS) - 16;
  88.  
  89.   #else
  90.       ret =  *((unsigned *) _heapbase + 1 ) -  __brklvl - 1;
  91.   #endif
  92.      return ret;
  93.   }
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.